<?php
if(isset($_POST['gpid']))
	{
		session_start();
		$gpid = $_POST['gpid'];
		require_once("../connection.php");
		$user = $_SESSION['user'];
	}
else
	require_once("php/connection.php");

$res = mysql_query("SELECT * FROM site_groups WHERE `id`='$gpid' AND `del`!='1'");
if(!$res) echo mysql_error();

if(mysql_numrows($res) == 0)
	echo '<div class="err_box">No such group exists my friend!</div>';
else
{
	$gp_name = mysql_result($res,0,'name');
	$gp_visibility = mysql_result($res,0,'visibility');
	$gp_description = mysql_result($res,0,'description');
	
	//checking if the present logged in user is a member or not
	$mem_yon = mysql_numrows(mysql_query("SELECT * FROM site_group_members WHERE `gpid`='$gpid' AND `fbid`='$user' AND `del`!='1'"));
	

	if($mem_yon > 0) // for the members of the circle
	{
		
		echo '<div id="stream_wrapper" style="position:relative;">
		<div id="stream_group_'.$gpid.'" style="padding:20px;min-height:350px" >		
		<img src="images/22.gif" /></div>
		
		<div style="height:125px;width:660px;" id="pb_wrapper_wrapper">
		<div style="width:700px;background:#fafafa;position:fixed;bottom:0px" id="pb_wrapper">
		
		<div style="border-top:1px dashed #aaa;padding-left:20px">
		<span class="small-font faded" id="stream_realtime_status"></span>
		</div>
		
		<div style="margin:10px;margin-top:5px">
		<div style="color:#aaa;padding:5px;border:1px solid #aaa;cursor:text;background:#fff" onclick=\'pb_alter("group_'.$gpid.'")\' id="pb_group_'.$gpid.'_control">Write a post..</div>';
		$type = "group_".$gpid; // setting the type for the post box
		echo '<div id="pb_'.$type.'" style="display:none;background:#fff">';
		$count = mysql_numrows(mysql_query("SELECT * FROM site_group_members WHERE `gpid`='$gpid' AND `del`!='1'"));
		if(isset($_POST['gpid'])) {
			include('post_box.php'); 
		}
		else {
			include('php/modules/post_box.php');
		}
		
		echo '</div><br>';		
		echo '</div>
		</div></div></div>';
		echo '<script>
		$(function() {
			init_stream('.$user.',"group_'.$gpid.'");
			clearTimeout(polling_timeout);
			if(gp_xhr!=undefined)
				gp_xhr.abort();
			init_gp_polling('.$user.',"group_'.$gpid.'");
		});		
		</script>';
		//the comment box
		
	}
	else
	{
		if($gp_visibility == "protected")
		{
			echo '<br><div class="err_box">You can view the stories but to post, you need request the admin</div>';
			echo '<br><hr><br>';
			echo '<div id="stream_group_'.$gpid.'"><img src="images/22.gif" /></div>';
			echo '<script>init_stream('.$user.',"group_'.$gpid.'");</script>';
		}
		else if($gp_visibility=="public")
		{
			echo '<br><div class="err_box">You need to join this circle to start posting.</div><br>';
			echo '<hr><br>';
			echo '<div id="stream_group_'.$gpid.'"><img src="images/22.gif" /></div>';
			echo '<script>init_stream('.$user.',"group_'.$gpid.'");</script>';
			
		} 
		else
		{
			echo '<br><div class="err_box">This is a closed circle. We can\'t show you anything. You need to reqest the mods to join this circle.</div>';
		}
		
	}
}

?>	